

function nextH = findMainPath(primaryPathTable, s, d, disp_loc, matrix)        
        %______________________________A Sender and it's Neighbors_______________________________________________            
        [neighborsS] = node_neighbors(s,matrix);%This function will return the neighbors for certain node.  
        
        %_______________________________Getting X & Y Coordinates______________________________________________
        [xS,yS] = find_Coordinates(s, disp_loc);%This function will return the X and Y for a node.
        [xD,yD] = find_Coordinates(d, disp_loc);%This function will return the X and Y for a destination node.
        
         %________________________________Distances____________________________________________ 

            %The distance between all the sender neighborhood nodes and the destination.
            [DBSND]= distanceBetweenSourceAndNeighbors(d,neighborsS,disp_loc);
            
         %________________________________Next Hop node____________________________________________  
%           nextH = nextHopeNode(DBSND, neighborsS);
%           inPath = lookingForNodeInArray(nextH, primaryPathTable); 
              [sortingNodes] = sortNodesAscending(DBSND, neighborsS); 
              lengthSN = length(sortingNodes);              
              i = 1;
              getOut = 0;
             while getOut == 0 && i ~= lengthSN
                nextH = sortingNodes(i);
                inPath = lookingForNodeInArray(nextH, primaryPathTable);
                if inPath == 0
                      getOut = 1;
                end
                 i = i + 1;
             end             
             if getOut == 0                 
                 nextH = -1;
             end
         
end